<template>
    <div class="address-warning">
        <!--{{allData}}-->
       <!--<Dispatch-list :nav-list="navList" :obj-data="objData" v-model="allData"/>-->
       <Dispatch-list v-model="allData"/>
    </div>
</template>
<script>
    import DispatchData from './datashow/Dispatchdata.vue'
    import DispatchList from './list/DispatchList.vue'

    export default {
        components: {
            DispatchList,
            DispatchData
        },
        data() {
            return {
                allData: {
                    navList: [],
                    objData: {},
                    current: '',
                    checkIndex: '0'
                },
                // navList: [],
                // objData: {},
                timer: null,
                index: null
            }
        },
        computed: {
            dataRefreshDialog() {
                return this.$store.state.num;
            },
            checkIndex() {
                return this.allData.checkIndex;
            },
            current() {
                return this.allData.current;
            }
        },
        watch: {
            dataRefreshDialog: function(newValue) {
                this.getNavList();
                this.getStatisticsData()
            },
            checkIndex:function (val) {
                this.getNavList();
                let data = {
                    orderDispatchStatus: {
                        value: this.allData.current,
                        searchModel: "equal",
                        page: 1
                    },
                    dispatchType: {
                        value: this.allData.checkIndex,
                        searchModel: "equal",
                        page: 1
                    }
                };
                this.$store.commit('pipe', {'value': data, 'name': 'express.order.table'});
            },
            current:function (val) {
                let data = {
                    orderDispatchStatus: {
                        value: this.allData.current,
                        searchModel: "equal",
                        page: 1
                    },
                    dispatchType: {
                        value: this.allData.checkIndex,
                        searchModel: "equal",
                        page: 1
                    }
                };
                this.$store.commit('pipe', {'value': data, 'name': 'express.order.table'});
            }
        },
        mounted() {
            this.getNavList();

            this.getStatisticsData()
            // this.timer = setInterval(() =>{
            //     this.$store.commit('refreshDialog');
            // }, 30000);
            this.$once('hook:beforeDestroy', () => {
                clearInterval(this.timer);
            })
        },
        methods: {
            getNavList() {   // 获取导航数据
                this.$http.get('express/order/nav?dispatchType=' + this.allData.checkIndex)
                    .then((response) => {
                        // this.navList = response.data.data;
                        this.allData.navList = response.data.data;
                        this.allData.current = this.allData.navList?this.allData.navList[0].type:'';
                    })
                    .catch((error) => {
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
            getStatisticsData() {  // 获取统计数据
                this.$http.get('express/order/dispatch_count')
                    .then((response) => {
                        // this.objData = response.data.data;
                        this.allData.objData = response.data.data;
                    })
                    .catch((error) => {
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },

        }
    }
</script>
<style lang="less">
</style>

